<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>title</title>
    <script src="resource/jquery214.js"></script>
    <script src="resource/fastclick.js"></script>
    <script src="resource/zeptomin.js"></script>
    <script src="resource/picker.js"></script>
    <script src="../script/api.js"></script>
    <script src="resource/md5.js"></script>
    <script type="text/javascript" src="../script/constants.js"></script>
    <script type="text/javascript" src="../script/aes.js"></script>
    <script type="text/javascript" charset="UTF-8" src="../script/naes.js"></script>
    <script type="text/javascript" src="../script/modeecb.js"></script>
    <script src="../script/tmd5.js"></script>
    <style>
  .odiv{
	   display:table;
	   background:#fff;
	   width:100%;
	   padding:5px;
	   border-top:1px solid #E1E1E1; 
	   border-bottom:1px solid #E1E1E1;
   }
   .idiv{
	   float: left;
	   font-size:15px;
	   margin-left: 10px;
	   height:40px;
	   line-height:40px;
   }
   .div_text{
	   float: right;
	   height:40px;
	   line-height:40px;
	   width:65%;
	   color: #8d8d8d;
	   font-size:15px;
	   text-align: right;
	   overflow:hidden;
	   white-space: nowrap; 
	   text-overflow: ellipsis;
	   margin-right:10px;
   }
   .ipt{
     border:none;
     outline:none;
     width:100%;
     font-size:16px;
   }
   .select {
	    padding-top:5px;
	    padding-bottom:5px;
		border: 0;
		appearance:none;
		background: #fff;
		color: #000;
		outline: medium none;
		width:100%;
		height:100%;
		font-size: 16px;
	}
   
   .userBnos{
        width: 100%;
        background: #fff;
        z-index: 9999;
        position: absolute;
        border:1px solid #ABABAB;
        display: none;
   }
   
   .userBno{
        width:100%;
        padding-left: 30%;
        padding-top: 4px;
        padding-bottom: 4px;
   }
   
   body {
    overflow-x:hidden;
    margin: 0;
   }
   html {
    overflow-x:hidden;
   }
   
label {cursor:pointer;height:40px;}
label i {font-size:18px;font-style:normal;display:inline-block;width:18px;height:18px;text-align:center;line-height:18px;color:#fff;vertical-align:middle;margin:-2px 2px 1px 0px;border:#2489c5 1px solid;}
input[type="checkbox"] {display:none;}
input[type="checkbox"]:checked + i {background:#2489c5;}
input[type="checkbox"]:disabled + i {border-color:#ccc;}
input[type="checkbox"]:checked:disabled + i {background:#ccc;}

    </style>
</head>
<body style="background:url(../../image/bj.png) repeat-x 0;background-size:100%;">
<div style="background:url(../../image/mainbg.png) no-repeat right 0 bottom 0%;">
<div>
       <header id="statusBar">
		<div style="width:100%;display:table;background: #27a8fa;position:fixed;border-bottom:1px solid #EAEAEA;z-index: 9999;height: 50px;" >
			<div style="float:left;width: 20%;height: 50px;line-height: 50px;" tapmode="presshover" onclick="api.closeWin();">
			  <div style="float:left;width: 30%;height: 50px;">
			   <img style="width: 24px;margin-top: 13px;" src="../image/back.png" />
			   </div>
			   <div style="float:left;width: 50%;color: #ffffff;">
			   返回
			   </div>
			</div>
			<div style="float:left;width: 60%;height: 50px;line-height: 50px;text-align: center;font-weight:bold;color: #ffffff;">
			 用户注册
			</div>
		</div>
	 </header>
          <div style="height:50px"></div>
          <input name="md5_passwd" id="md5_passwd" type="hidden" />
          <input name="sm" id="sm" type="hidden" />
          <input name="type" id="type" type="hidden" value="1"/>
          <input id="phone_yz" name="phone" style="display:none" >
          <input  type="hidden" id="root"/>
          
          <div class='odiv'>  
          <div class='idiv'>手机号</div>
          <div class="div_text" style="margin-right:20px;">
          <input  type="text" class="ipt" id="phone" name="phone" placeholder="请输入手机号"/>
          </div>
          </div>
          <div class='odiv'>  
          <div class='idiv'>验证码</div>
          <div class="div_text" style="margin-right:20px;">
          <input  type="text" id="yzmtx" name="yzmtx" style="border:none;outline:none;width:50%;font-size:16px;" id="code" placeholder="请输入验证码"/>
          <input  type="button" style="border:none;outline:none;width:50%;background: #fff;" tapmode="presshover" id="yzmhq" onclick="getYzm(this)" value="获取验证码"/>
          </div> 
          </div>
          <div class='odiv'>  
          <div class='idiv'>密码</div>
          <div class="div_text" style="margin-right:20px;">
          <input  type="password" id="passwd" name="passwd" class="ipt" placeholder="请输入6-16的数字字母组合密码"/>
          </div> 
          </div>
          
          <div class='odiv'>  
          <div class='idiv' id="bankCard">确认密码</div>
          <div class="div_text" style="margin-right:20px;">
          <input  type="password" id="passwd1" name="passwd1" class="ipt" placeholder="请输入6-16的数字字母组合密码"/>
          </div> 
          </div>
         
          <div class='odiv'>  
          <div style="width:80%;text-align: center;margin: 0 auto;">
          <div id="btn1" onclick="test()" style="float: left;width:48%;height:35px;background: #27a8fa;margin:0 auto;color:#fff;line-height: 35px;border-radius:5px;">扫描二维码</div>
          <div id="btn2" onclick="sdsr()" style="float: right;width:48%;height:35px;background: #27a8fa;margin:0 auto;color:#fff;line-height: 35px;border-radius:5px;">输入税号</div> 
          </div>
          </div>
          
          <div class='odiv' id="hide" style="display:none;">  
          <div class='idiv'>企业税号</div>
          <div class="div_text" style="margin-right:20px;">
          <input  type="text" class="ipt" placeholder="请输入税号(选填)" id="taxcode" name="taxcode"/>
          </div> 
          </div>
          
          <div class='odiv'>  
          <div class='idiv' id="bankCard">功能模块</div>
          <div class="div_text" style="margin-right:20px;">
          <input  type="text" class="ipt" id="rootname" placeholder="请选择功能模块" readonly="true" onclick="module();"/>
          </div> 
          </div>
           <div style="padding: 20px 0;width:100%;text-align: center;" onclick="zc()" tapmode="presshover">
			<div style="width:80%;height:35px;background: #27a8fa;margin:0 auto;color:#fff;line-height: 35px;border-radius:5px;">注册</div>
		  </div>
</div>
			
</div>	
<script type="text/javascript">
   apiready = function(){
      if(api.systemType == "ios"){
		   document.getElementById("statusBar").style.background = "#298cb4";
		}
      $api.fixStatusBar( $api.dom('header') );
      $api.setStorage('cs','3');
//    if (api.systemType=='ios') {
//      var header = $api.byId('jsheader');
//      $api.fixIos7Bar(header);
//    }
   }
   
   
   function module(){
       var UIMultiSelector = api.require('UIMultiSelector');
		 UIMultiSelector.open({
		     rect: {
		         h: 295
		     },
		     text: {
		         title: '功能模块',
		         leftBtn: '取消',
		         rightBtn: '确认',
		         selectAll: '所有模块'
		     },
		     max: 0,
		     singleSelection: false,
		     styles: {
		         bg: '#fff',      
		         mask: 'rgba(0,0,0,0.5)',
		         title: {
		             bg: '#fff',
		             color: '#27a8fa',
		             size: 16,
		             h: 44
		         },
		         leftButton: {
		             bg: '#fff',    
		             w: 80,
		             h: 35,
		             marginT: 5,
		             marginL: 8,
		             color: '#FF6347',
		             size: 14
		         },
		         rightButton: {
		             bg: '#fff',    
		             w: 80,
		             h: 35,
		             marginT: 5,
		             marginR: 8,
		             color: '#32CD32',
		             size: 14
		         },
		         item: {
		             h: 50,
		             bg: '#FAFAFA',
		             bgActive: '#27a8fa',
		             bgHighlight: '#27a8fa',
		             color: '#8d8d8d',
		             active: '#fff',
		             highlight: '#fff',
		             size: 16,
		             lineColor: '#EBEBEB',
		             textAlign: 'center'
		         },
			     icon: {                            //（可选项）JSON 类型；每个选项的状态图标样式，若不传则不显示选中的状态图标
			        w: 0,                         //（可选项）数字类型；图标的高度；默认：20
			        h: 0,                         //（可选项）数字类型；图标的高度；默认：w
			        marginT: 11,                   //（可选项）数字类型；图标的上边距；默认：(item.h - h) / 2
			        marginH: 8,                    //（可选项）数字类型；图标的横向边距，与 align 的对齐方向相关；默认：8
			        bg: '#fff',                    //（可选项）字符串类型；图标未选中时的背景，支持 rgb、rgba、#、img；默认：rgba(0,0,0,0)
			        bgActive: '#fff',              //（可选项）字符串类型；已选中图标的背景，支持 rgb、rgba、#、img；默认：bg
			        bgHighlight: '#fff',           //（可选项）字符串类型；选项的高亮背景，支持 rgb、rgba、#、img；默认：bg
			        align: 'left'                  //（可选项）字符串类型；图标相对与选项的对齐方式：'left|right'；默认：left
			     }
		     },
		     animation: true,
		     items:  [{
		                 id: '2',
				         text: '金穗采购',
				         status: 'selected'
				     }, {
				         id: '4',
				         text: '企业收款',
				         status: 'normal'
				     }, {
				         id: '1',
				         text: '公安便民服务',
				         status: 'normal'
				     }, {
				         id: '3',
				         text: '公安娱乐业',
				         status: 'normal'
				     }]
		 }, function(ret, err) {
		     if (ret) {
		         if(ret.eventType == "clickLeft"){
		            UIMultiSelector.hide();
		         }else if(ret.eventType == "clickRight"){
		            console.log(JSON.stringify(ret));
		            if(ret.items.length>0){
		               var root = "";
		               var rootname = "";
		               for(var i = 0;i<ret.items.length;i++){
		                   root += ret.items[i].id;
		                   rootname += ret.items[i].text+",";
		               }
		               $("#root").val(root);
		               $("#rootname").val(rootname);
		               UIMultiSelector.hide();
		            }else{
		               api.alert({msg: "请选择功能模块！"});
		            }
		         }
		     } else {
		         alert(JSON.stringify(err));
		     }
		 });
    }
    
    function sdsr(){
$("#hide").show();
$("#type").val("1");
$("#taxcode").val("");
}
 function test(){
      $("#hide").show();
      $("#type").val("2");

  var FNScanner = api.require('FNScanner');
		FNScanner.openScanner({
		    autorotation: true
		}, function(ret, err) {
			var content = JSON.stringify(ret.content);
            console.info(JSON.stringify(ret));

		    var userid_val = content.split('&')[4];
		    $("#sm").val(userid_val);
		    if(userid_val!=undefined){
		      $("#taxcode").val("已扫描");
		     }
		});

  }

	function back(){
         api.closeWin();
	}


  function validPsw(passwd) {
  	var password = passwd
  	var num = 0;
  	var number = 0 ;
  	var letter = 0 ;
  	var bigLetter = 0 ;
  	var chars = 0 ;

  	if (password.search(/[0-9]/) != -1) {
  		num += 1;
  		number =1;
  	}
  	if (password.search(/[A-Z]/) != -1) {
  		num += 1;
  		bigLetter = 1 ;
  	}
  	if (password.search(/[a-z]/) != -1) {
  		num += 1;
  		letter = 1 ;
  	}
  	if (password.search(/[^A-Za-z0-9]/) != -1) {
  		num += 1;
  		chars = 1 ;
  	}
  	if (num >= 2 && (password.length >= 6 && password.length <= 16)) {

      return true;
  	}else if(password.length < 6 || password.length > 16){

        alert("密码由6-16个字符组成!");
      return false;
  	}else if(num == 1){
  		if(number==1){
          alert("不能全为数字!");

        return false;
  		}
  		if(letter==1){
          alert("不能全为字母!");

        return false;
  		}
  		if(bigLetter==1){
          alert("不能全为字母!");

        return false;
  		}
  		if(chars==1){
          alert("不能全为字符!");

        return false;
  		}

  	}
  }

  function check0(){
   var phone = document.getElementById("phone").value;
   var phone_yz = document.getElementById("phone_yz").value;
   var taxcode = document.getElementById("taxcode").value;
   var passwd = document.getElementById("passwd").value;
   var passwd1 = document.getElementById("passwd1").value;
   var yzmtx = document.getElementById("yzmtx").value;
   var type = document.getElementById("type").value;
   var sm = document.getElementById("sm").value;

    if(false==validPsw(passwd)){
       $("#wzc").show();
       $("#yzc").hide();
       return false;
    };
    var passwd = hex_md5(passwd);
    var passwd1 = hex_md5(passwd1);

    if( passwd != passwd1 ){
      alert("两次输入密码不同");
       $("#wzc").show();
    $("#yzc").hide();
      return false;

    }

    if(yzmtx == "" || yzmtx == "undefined"){
      api.alert({msg: "请输入验证码"});
      return false;
    }

    if(phone.length != 11){//验证手机号

      api.alert({
          title: '信息注册',
          msg: '输入正确手机号',
      });
    $("#wzc").show();
    $("#yzc").hide();
      return false;
    }

    document.getElementById("md5_passwd").value = passwd ;
    $("#wzc").show();
    $("#yzc").hide();
    return true;
  }


  function zc() {
      var aeskey = api.loadSecureValue({
        sync: true,
        key: 'aeskey'
      });
      var salt = api.loadSecureValue({
	       sync: true,
	       key: 'salt'
	  });
  	 var phone = document.getElementById("phone").value;
     var taxcode = document.getElementById("taxcode").value;
	 var passwd = document.getElementById("passwd").value;
	 var passwd = hex_md5(passwd);
	 document.getElementById("md5_passwd").value = passwd ;
	 var md5_passwd = document.getElementById("md5_passwd").value;
	 var sm = document.getElementById("sm").value;
	 var type = document.getElementById("type").value;
	   if(taxcode!='暂无（选填）'&&taxcode!="已扫描"&&taxcode!=""){
	    sm = taxcode ;
	   }
     var yzmtx = document.getElementById("yzmtx").value;
     var a = check0();
    if(a){
    $("#wzc").hide();
    $("#yzc").show();
    _openid = phone;
      var content = {"openid":phone,"phone":phone,"md5_passwd":md5_passwd,"sm":sm,"type":type,"deviceName":api.deviceName,"yzm":yzmtx};
      var callback = function(ret, err){
            //console.log(JSON.stringify(ret));
            if (ret) {
			  var res = Decrypt(ret.ret,aeskey);
			  var data = eval("("+ res +")");
	  		      if(data.flag=="Y"){
	  		        $api.setStorage('loginid',data.id);
	  		        $api.setStorage('openid',_openid);
	                $api.setStorage('dl_phone',phone);
	    			$api.setStorage("taxcode",ret.taxcode);
	    			$api.setStorage("LOGIN_FLAG","Y");
	    			$api.setStorage("rootid",$("#root").val());
	    			api.sendEvent({
		                name:'reloadIndex'
	                });
	                api.alert({msg:'注册成功'});
	                api.closeToWin({
		                name: 'root'
	                });
	  		      }else if(data.flag=="N"){
		  		      api.alert({msg:'账号已注册'});
		  		      $("#wzc").show();
		              $("#yzc").hide();
	  		      }else if(data.flag=="D"){
	                api.alert({msg:'验证码错误'});
	                $("#wzc").show();
	                $("#yzc").hide();
	              }else{
	  		       api.alert({msg:'账号注册失败'});
	  		      }

       		 }else{
       		 	api.alert({msg:'注册失败'});
       		 	$("#yzc").hide();
                $("#wzc").show();
       		 }
      }
      encApiAjax(JSON.stringify(content),url.userreg,callback);
      }
  }
var sj ='0';


    var timer = null;
    var countdown=60;

    function settime(val) {
      if (countdown == 0) {
        val.removeAttribute("disabled");
        val.value="获取验证码";
        countdown = 60;
        $("#yzm").val("");
        window.clearTimeout(timer);
      } else {
        val.setAttribute("disabled", true);
        val.value="重新发送(" + countdown + ")";
        countdown--;
        timer = setTimeout(function() {
          settime(val);
        },1000);

      }

    }

    function getYzm(e){

      if($("#phone").val()!=null||$("#phone").val()!=null){
        var phone = $("#phone").val();
        if(phone.length != 11){//验证手机号
          alert("输入正确手机号");
          return false;
        }
        var yz = $api.getStorage('cs')-1;
          if(yz<0){
              alert("获取验证码过于频繁，请5分钟后再试")
              countdown = 300
              settime(e);
              $api.setStorage('cs','3');
              return false;
          }else{
            $api.setStorage('cs',yz);
        }
        settime(e);
        var aeskey = api.loadSecureValue({
           sync: true,
           key: 'aeskey'
        });
        var salt = api.loadSecureValue({
	       sync: true,
	       key: 'salt'
	    });
//	  api.require('ipAddress').getIp(
//	   function(ret, err) {
            var ip = "0.0.0.0";
		    var content = {"phone":phone,"ip":ip,type:"0"};
	        var callback = function(ret, err){
		             if(ret.flag=="Y"){
			          alert("验证码已发送，请稍候");
			         }else if(ret.flag=="N"){
			            alert("请求验证码过于频繁，请稍后再试！");
			         }else if(ret.flag=="W"){
			            alert("账号已存在！");
			         }else {
			            alert("验证码发送失败，请重试");
			         }
		        }
		    encApiAjax(JSON.stringify(content),url.hqccode,callback);
//       });
      }else{
        alert("请先输入手机号码")
      }
    }
</script>	
</body>
</html>